/*
 * Created by SharpDevelop.
 * User: K 3 N ! L
 * Date: 12/7/2008
 * Time: 5:58 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data;

namespace ChallanSystem
{
	/// <summary>
	/// Description of ProdCategorySearch.
	/// </summary>

	public class ProdCategorySearch
	{
		private static string strCon = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=./Data/DB.mdb" ;
		private OleDbConnection myCon = new OleDbConnection(strCon);
		
		public ProdCategorySearch()
		{
		}
		
		public DataSet View()
		{
//			SqlParameter p = new SqlParameter();
//			SqlCommand s = new SqlCommand();
//
//			p = s.Parameters.AddWithValue("?", Convert.ToInt32(1));
			string sqlStr = IConstantQuery.SELECT_PRODUCT_CATEGORY;
			//Make a DataSet object
			DataSet myDataSet = new DataSet();
			//Using the OleDbDataAdapter execute the query
			OleDbDataAdapter myAdapter = new OleDbDataAdapter( sqlStr , myCon );
			//Fill the DataSet with the Table 'Product'
			myAdapter.Fill(myDataSet,"Product_Category");
			return myDataSet;
		}
		
		public bool insertCategory(string categoryName)
		{
			string sqlStr = IConstantQuery.INSERT_PRODUCT_CATEGORY;
			sqlStr += "('"+categoryName+"')";
			MessageBox.Show("sql str : "+sqlStr);
			
			bool flag = false;
			
			OleDbCommand myCmd = new OleDbCommand( sqlStr , myCon );
			try
			{
				myCon.Open();
				//Execute the statement
				myCmd.ExecuteNonQuery();
				//statusBar.Text="Connected - Now you can add records";
				MessageBox.Show("New Category Created");
				flag = true;
			}
			catch( OleDbException a)
			{
				MessageBox.Show("Error in inserting! \n" + a.ToString(), "Error");
			}
			finally
			{
				myCmd.Dispose();
				myCon.Close() ;
				//myCon.Dispose();
			}
		return flag;
	}

}
}
